import React, { Component } from 'react';
import {
	StyleSheet, Text, View, TouchableOpacity, PixelRatio
} from "react-native";
import { GLOBAL } from '../../../../../config/global';
import MethodUtil from '../../../../../utils/MethodUtil';
import { creditType } from '../../../../../config/definition';
import { style } from '../../../../../theme/style';

const scale = GLOBAL.SCALE;
export class CreditApproveItem extends Component {
	constructor(props) {
		super(props);
	}

	render () {
		const { itemInfo, dictKey, goDetail, choice } = this.props;
		const { creditApplyVO, auditResultName, taskId, taskName, taskDefinitionKey, formKey } = itemInfo;
		const { creditApplyCode, creditApplyId, companyName, creditApplyAmount, createByName, bizTeamName, createTime, creditKind } = creditApplyVO || {};
		return (
			<TouchableOpacity key={creditApplyCode + companyName} activeOpacity={.5} style={styles.orderCell}
				onPress={() => {
					goDetail({
						creditApplyId,
						taskName,
						taskId,
						taskDefinitionKey,
						formKey,
						resUrl: 'ApprovePage',
					}, '授信审批')
				}}>
				<View style={styles.order}>
					<View style={styles.orderHeadView}>
						<View style={styles.orderHead}>
							<View style={styles.orderHeadLeft}>
								<Text style={styles.orderHeadText}>{creditApplyCode || null}</Text>
								{/* <Image source={conPic} style={styles.conImage} /> */}
							</View>
							<Text style={styles.statusText}>{auditResultName}</Text>
						</View>
						<Text style={{ fontSize: 10 * scale, paddingBottom: 12 * scale, color: '#848A96' }}>(业务组织：{choice.corpName || '-'})</Text>
					</View>
					<View style={styles.orderMain}>
						<View style={styles.orderCol}>
							<Text style={styles.orderText}>{creditType[creditKind] ? creditType[creditKind] + ':' : ''}</Text>
							<Text style={styles.orderVal}>
								{
									companyName ? (
										companyName.length > 8 ? (companyName.substr(0, 8) + '...') : companyName
									) : null
								}
							</Text>
						</View>
						<View style={styles.orderCol}>
							<Text style={styles.orderText}>本次申请额度：</Text>
							<Text style={styles.orderVal}>{MethodUtil.toThousands(MethodUtil.countObj.divide(creditApplyAmount || 0, 10000, 2)) + '万元'}</Text>
						</View>
						<View style={styles.orderCol}>
							<Text style={styles.orderText}>任务名称：</Text>
							<Text style={styles.orderVal}>{taskName || ''}</Text>
						</View>
						<View style={styles.orderCol}>
							<Text style={styles.orderText}>申请人：</Text>
							<Text style={styles.orderVal}>{createByName || ''}</Text>
						</View>
						<View style={styles.orderCol}>
							<Text style={styles.orderText}>申请时间：</Text>
							<Text style={styles.orderVal}>{createTime || ''}</Text>
						</View>
						<View style={styles.flexOrder}>
							<Text style={styles.orderName}>产品线：</Text>
							<Text style={styles.orderTitle}>{bizTeamName || ''}</Text>
						</View>
					</View>
				</View>
			</TouchableOpacity>
		)
	}
}

const styles = StyleSheet.create({
	orderCell: {
		width: 375 * scale,
		backgroundColor: '#fff',
		alignItems: 'center',
		marginBottom: 12 * scale,
	},
	order: {
		width: 351 * scale,
	},
	orderHead: {
		width: 351 * scale,
		height: 44 * scale,
		justifyContent: 'space-between',
		alignItems: 'center',
		flexDirection: 'row',
	},
	orderHeadView: {
		width: 351 * scale,
		borderBottomColor: '#e4e4e4',
		borderBottomWidth: 1 / PixelRatio.get(),
	},
	orderHeadLeft: {
		height: 44 * scale,
		alignItems: 'center',
		flexDirection: 'row',
	},
	orderHeadText: {
		fontSize: 14 * scale,
		color: '#222',
		flexWrap: 'wrap'
	},
	statusText: {
		fontSize: 13 * scale,
		color: style.color.themeColor,
	},
	orderMain: {
		flexDirection: 'row',
		paddingTop: 8 * scale,
		paddingBottom: 8 * scale,
		flexWrap: 'wrap'
	},
	orderCol: {
		flexDirection: 'row',
		alignItems: 'center',
		height: 25 * scale,
		width: 175.5 * scale,
	},
	orderText: {
		fontSize: 12 * scale,
		color: '#8B8B8B'
	},
	orderVal: {
		fontSize: 12 * scale,
		color: '#000'
	},
	flexOrder: {
		flexDirection: 'row',
		width: 308 * scale,
	},
	orderName: {
		fontSize: 12 * scale,
		color: '#8B8B8B'
	},
	orderTitle: {
		flexDirection: 'row',
		paddingRight: 15 * scale,
		fontSize: 12 * scale,
	},
})